package com.fjwt.gz.proxy.ctrl.score.stat;


import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.StatScoreNumMonthDTO;
import com.fjwt.gz.proxy.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.StatScoreNumMonthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *  统计积分总情况变化和变化接口
 * @author myf
 */
@RestController
@RequestMapping("/api/statScoreNumMonth")
@Slf4j
public class StatScoreNumMonthController extends CommonCtrl {

    @Autowired
    private StatScoreNumMonthService statScoreNumMonthService;

    /**
     * 查询积分明细
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_DATA_REPORT_SCORE_USE_INFO')")
    @GetMapping
    public ApiRes list() {
        StatScoreNumMonthDTO scoreNumMonthDTO = getObject(StatScoreNumMonthDTO.class);

        return ApiRes.page(statScoreNumMonthService.selectScoreNumMonthStatistics(getIPage(), scoreNumMonthDTO));
    }

    /**
     * 导出报表
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_DATA_REPORT_SCORE_USE_INFO_EXPT')")
    @PostMapping("/export")
    public ApiRes export() {
        StatScoreNumMonthDTO scoreNumMonthDTO = getObject(StatScoreNumMonthDTO.class);
        log.info("运营端导出积分明细报表，请求地址：/api/statScoreRecord/export，请求参数：{}", scoreNumMonthDTO);
        statScoreNumMonthService.export(scoreNumMonthDTO, getCurrentUser().getSysUser());
        return ApiRes.ok();
    }
}
